package com.geotmt.billingcenter.common.result;

import lombok.Data;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description 接口返回类
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/3/11 18:15
 * @Version     v1
 **/
@Data
public class ResponseResult {

    private Integer code;
    private Integer status;
    private String msg;
    private Object data;
    private boolean success;

    public static ResponseResult build(Integer code, String msg, Object data, boolean success) {
        ResponseResult result = new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        result.setSuccess(success);
        return result;
    }

    public static ResponseResult build(Integer code,Integer status, String msg, Object data, boolean success) {
        ResponseResult result = new ResponseResult();
        result.setStatus(status);
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        result.setSuccess(success);
        return result;
    }

    public static ResponseResult error(Object data) {
        ResponseResult result = new ResponseResult();
        result.setCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        result.setMsg("服务器异常,请稍后重试");
        result.setSuccess(false);
        result.setData(data);
        return result;
    }

    public static ResponseResult notFound(Object data) {
        ResponseResult result = new ResponseResult();
        result.setCode(HttpServletResponse.SC_NOT_FOUND);
        result.setMsg("无效的请求路径");
        result.setSuccess(false);
        result.setData(data);
        return result;
    }

    public static ResponseResult ok(Object data) {
        ResponseResult result = new ResponseResult();
        result.setCode(HttpServletResponse.SC_OK);
        result.setMsg("请求成功");
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

}
